<template>
  <div>
    <div class="table-line">
      <ul>
        <li v-for="(data, index) in dataList" :key="index" :class="{light: (index % 2 !==0)}" @click="changeDataByLine(data)" @dblclick="getDetail(data)">
          <div class="checkbox"><input type="checkbox" v-model="data.checked" @click="changeData"/></div>
          <div class="name">{{data.tabName}}</div>
          <div class="status"><span :style="{'background-color': state[data.state].color}">{{state[data.state].name}}</span></div>
          <div class="desc">{{data.docNo}}</div>
          <div class="time">{{data.createtime}}</div>
        </li>
      </ul>
    </div>
    <detail :show="showDetail" :id="currentId" @close="showDetail = false"/>
  </div>
</template>

<script>
import Detail from './detail';

const state = {
  0: {
    name: '未审核',
    color: '#FF9900'
  },
  1: {
    name: '已审核',
    color: '#ff9900'
  },
  2: {
    name: '未汇总',
    color: '#7cdda7'
  },
  100: {
    name: '已汇总',
    color: '#348fe2'
  },
  999: {
    name: '已生效',
    color: '#b6c2c9'
  }
};

export default {
  name: 'detentionList',
  props: ['dataList'],
  components: {
    Detail
  },
  data() {
    return {
      state,
      showDetail: false,
      currentId: ''
    };
  },
  methods: {
    getDetail(data) {
      this.showDetail = true;
      this.currentId = data.id;
    },
    changeData() {
      this.$emit('dataChange');
    },
    changeDataByLine(data) {
      data.checked = !data.checked;
      this.$emit('dataChange');
    }
  }
};
</script>

<style lang="scss" scoped>
.table-line {
  background-color: rgb(233, 233, 233);
  border: 1px solid rgb(233, 233, 233);

  ul {
    li {
      height: 32px;
      line-height: 32px;
      list-style-type: none;
      display: flex;
      padding: 10px;
      flex-wrap: nowrap;
      justify-content: flex-start;

      &.light {
        background-color: #fff;
      }

      .checkbox {
        width: 30px;
      }

      .name {
        width: 15%;
      }

      .status {
        width: 20%;

        span {
          border-radius: 5px;
          padding: 5px 10px;
          color: #fff;
          font-size: 14px;
        }
      }

      .desc {
        width: 20%;
      }

      .time {
        align-self: flex-end;
        flex: 1;
        text-align: right;
      }
    }
  }
}
</style>
